package com.corx.network.config;

import com.corx.network.core.handler.NetworkStateHandler;
import com.corx.network.core.manager.NetworkStateManager;
import com.corx.network.mysqlstorage.handler.JdbcNetworkStateHandler;
import com.corx.network.mysqlstorage.hub.DeviceRepositoryHub;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author gx
 * @version 1.0.0
 */
@Configuration
public class NetworkStateManagerAutoConfiguration {


    @Bean
    @ConditionalOnMissingBean
    public NetworkStateHandler networkStateHandler(DeviceRepositoryHub hub) {
        NetworkStateHandler handler = new JdbcNetworkStateHandler(hub);
        return handler;
    }

    @Bean
    @ConditionalOnMissingBean
    public NetworkStateManager networkStateManager(List<NetworkStateHandler> handlers) {
        NetworkStateManager manager = new NetworkStateManager();
        handlers.forEach(manager::register);
        return manager;
    }

}
